package com.isunland.managesystem.entity;

import android.content.Context;
import com.isunland.managesystem.utils.LogUtil;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangyanan email:ynwang2015@126.com
 * @ClassName: ReceiptDetailLab
 * @Description: 表单明细单例类.
 * @date 2016年1月26日
 */
public class ReceiptDetailLab {
  private Context mAppContext;// 保存一个context对象,很多地方会用到.
  private ArrayList<RProInvoiceRecdSub> mList;// 单例中的数据.
  private boolean isUnsaved = false;// 是否有未保存的数据,用于退出时提示用户保存.
  private static ReceiptDetailLab sLib;// 单例对象.

  private ReceiptDetailLab(Context appContext) {
    mAppContext = appContext;
    mList = new ArrayList<RProInvoiceRecdSub>();
  }

  public static ReceiptDetailLab get(Context c) {
    if (sLib == null) {
      sLib = new ReceiptDetailLab(c.getApplicationContext());
    }
    return sLib;
  }

  public boolean isUnsaved() {

    return isUnsaved;
  }

  public void setUnsaved(boolean isUnsaved) {
    this.isUnsaved = isUnsaved;
    LogUtil.i("isUnSaved=" + isUnsaved);
  }

  public ArrayList<RProInvoiceRecdSub> getList() {
    return mList;
  }

  public void addAll(List<RProInvoiceRecdSub> tasks) {
    mList.addAll(tasks);
  }

  public void removeAll() {
    mList.clear();
  }

  public void remove(String id) {
    RProInvoiceRecdSub item = null;
    for (RProInvoiceRecdSub c : mList) {
      if (c.getId().equalsIgnoreCase(id)) {
        // mList.remove(c);
        item = c;
      }
    }

    if (item != null) {
      mList.remove(item);
    }
  }

  public RProInvoiceRecdSub getItem(String id) {
    for (RProInvoiceRecdSub c : mList) {
      if (c.getId().equalsIgnoreCase(id)) return c;
    }
    return null;
  }
}
